package cwb1;

import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.Test;

import com.google.appengine.api.datastore.EntityNotFoundException;
import com.google.appengine.tools.development.testing.LocalDatastoreServiceTestConfig;
import com.google.appengine.tools.development.testing.LocalServiceTestHelper;

public class DivisionRegistryTest {

	private final LocalServiceTestHelper helper = new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig());
	@Before
	public void setUp() throws Exception {
		helper.setUp();		
	}

	public void tearDown() {
		helper.tearDown();
	}
	
	@Test
	public void addDivision() {
		Course course = new Course("analyse 3", "Dierckx", "analyse 3",3);
		
		User userTest = new User("cbw4", "1",1,"password");
		course.addUserToCourse(userTest);
		
		User userTest2 = new User("cbw5", "1",1,"password");
		course.addUserToCourse(userTest2);
		
		DivisionRegistry divisionRegistryTest = DivisionRegistry.getInstance();
		divisionRegistryTest.add(course);
		try {
			assertEquals(true, divisionRegistryTest.get(course.getId()).equals(course));
			assertEquals(2, divisionRegistryTest.get(course.getId()).getStudentsId().size());
		}
		
		catch (EntityNotFoundException e) {
			fail("Division not collected form the database");
		}
		
	}

}
